<template>
    <div>
        <svg-icon :icon-class="isFullScreen?'exit-fullscreen':'fullscreen'" @click="click" />
    </div>
</template>

<script lang="ts">
import {defineComponent, onMounted, onUnmounted, ref} from "vue";
import { ElMessage } from 'element-plus'
import screen from 'screenfull'

export default defineComponent({
    name:'Screenfull',
    setup(){
        const isFullScreen=ref(false)
        const click=()=>{
            if (!screen.isEnabled){
                ElMessage({
                    message:'you browser can not work',
                    type: 'warning'
                })
                return false
            }
            screen.toggle()
        }
        const change=()=>{
            isFullScreen.value=screen.isFullscreen
        }
        const init=()=>{
            if (screen.isEnabled){
                screen.on('change',change)
            }
        }
        onMounted(()=>{
            init()
        })
        onUnmounted(()=>{
            if (screen.isEnabled){
                screen.off('change',change)
            }
        })
        return{
            isFullScreen,
            click
        }

    }
})

</script>

<style scoped>
.screenfull-svg {
  display: inline-block;
  cursor: pointer;
  fill: #5a5e66;;
  width: 20px;
  height: 20px;
  vertical-align: 10px;
}
</style>
